from selenium.webdriver.common.by import By
from pages.base_page import BasePage
from config.config import HOST
'''财务页面'''


class KownlegePage(BasePage):
    # 定位添加知识
    add_knowledge_locator = (By.CSS_SELECTOR, 'body > div.container > div.row > div:nth-child(2) > div > div.pull-right > a')
    # 添加应收款页面url
    url = 'http://{}/crm/index.php?m=knowledge'.format(HOST)
    # 定位第一条知识
    first_knowlege_locator = (By.CSS_SELECTOR, '#form1 > table > tbody > tr > td:nth-child(1) > input')
    # 定位查看
    look_locator = (By.LINK_TEXT, '查看')
    # 定位编辑
    edit_locator = (By.LINK_TEXT, '编辑')
    # 定位删除
    del_knowlege_locator=(By.ID,'delete')
    # 定位不选择任务，直接点击删除的提示语
    del_unselect_tips_locator = (By.CSS_SELECTOR, 'body > div.container > div.alert.alert-error')

    def get_knowlege_url(self):
        '''获取知识页面url'''
        return self.current_url()

    def click_add_knowlege(self):
        '''点击添加知识'''
        self.driver.find_element(*self.add_knowledge_locator).click()

    def select_first_knowlege(self):
        '''选择第一条知识'''
        self.driver.find_element(*self.first_knowlege_locator).click()

    def click_look(self):
        '''点击查看'''
        self.driver.find_element(*self.look_locator).click()

    def click_edit(self):
        '''点击编辑'''
        self.driver.find_element(*self.edit_locator).click()

    def click_del_knowlege(self):
        '''点击删除'''
        self.driver.find_element(*self.del_knowlege_locator).click()

    def del_knowlege_unselect_tips(self):
        '''获取不选择任务，直接删除的提示语'''
        err_tip = self.driver.find_element(*self.del_unselect_tips_locator).text
        return err_tip